package com.zunipe.trainticketsystem;

import android.app.Application;

import com.zunipe.trainticketsystem.database.dao.OrderDao;
import com.zunipe.trainticketsystem.database.dao.TrainDao;
import com.zunipe.trainticketsystem.database.dao.UserDao;
import com.zunipe.trainticketsystem.database.entity.Train;
import com.zunipe.trainticketsystem.database.entity.User;

import java.util.Random;

public class TrainTicketApplication extends Application {
    private static TrainTicketApplication instance;
    private TrainDao trainDao;
    private UserDao userDao;
    private OrderDao orderDao;
    private final String[] perCharList = {"K", "G", "T"};
    private final String[] localList = {"南昌", "北京", "上海", "广东", "南京", "重庆", "成都"};
    public static final String CHANNEL_ID = "Train";

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;

        trainDao = new TrainDao(this);
        userDao = new UserDao(this);
        orderDao = new OrderDao(this);


        generateNewTrain();

        userDao.insert(new User("张三", "10002"));
        userDao.insert(new User("李四", "10003"));
        userDao.insert(new User("王五", "10004"));
        userDao.insert(new User("刘力", "10005"));
        userDao.insert(new User("宋蛤", "10006"));
        userDao.insert(new User("你", "10001"));
    }

    public void generateNewTrain() {
        Random r = new Random();
        String preChar = perCharList[r.nextInt(perCharList.length)];
        String number = String.valueOf(r.nextInt(9999));
        trainDao.insert(new Train(preChar + number, localList[r.nextInt(localList.length)],
                localList[r.nextInt(localList.length)], "07:30", "12:13", "二等", (double) r.nextInt(1000), r.nextInt(10)));
        trainDao.insert(new Train(preChar + number, localList[r.nextInt(localList.length)],
                localList[r.nextInt(localList.length)], "07:30", "12:13", "一等", (double) r.nextInt(1000), r.nextInt(10)));
        trainDao.insert(new Train(preChar + number, localList[r.nextInt(localList.length)],
                localList[r.nextInt(localList.length)], "07:30", "12:13", "特等", (double) r.nextInt(1000), r.nextInt(10)));
        trainDao.insert(new Train(preChar + number, localList[r.nextInt(localList.length)],
                localList[r.nextInt(localList.length)], "07:30", "12:13", "无座", (double) r.nextInt(1000), r.nextInt(10)));
    }


    public UserDao getUserDao() {
        return userDao;
    }

    public OrderDao getOrderDao() {
        return orderDao;
    }

    public TrainDao getTrainDao() {
        return trainDao;
    }

    public static TrainTicketApplication getInstance() {
        return instance;
    }
}
